package playground.fibu.ejb.entity;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table
public class Booking extends BaseEntity {

	private double amount;
	private String text;

	@ManyToOne(optional = false)
	private Account debitAccount;

	public Booking() {
		debitAccount = new Account();
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Account getDebitAccount() {
		return debitAccount;
	}

	public void setDebitAccount(Account debitAccount) {
		this.debitAccount = debitAccount;
	}

	// This must return true for another Account object with same key/id.
	public boolean equals(Object other) {
		return other instanceof Booking && (id != null) ? id
				.equals(((Booking) other).id) : (other == this);
	}

	// This must return the same hashcode for every Account object with the same
	// id.
	public int hashCode() {
		return id != null ? this.getClass().hashCode() + id.hashCode() : super
				.hashCode();
	}

	// Override Object#toString() so that it returns a human readable String
	// representation.
	// It is not required by the Converter or so, it just pleases the reading in
	// the logs.
	public String toString() {
		return "Booking[" + id + "," + text + "," + amount + "]";
	}
}
